/**
Copyright 2011 Patrick Devaney

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include <iostream>
#include <string.h>
#include <math.h>
#define _USE_MATH_DEFINES
using namespace std;

/*
File purpose:
main.cpp includes this, and this function seamlessly performs
I/O and calculations.
*/

int surfacearea(void) {
// As I've done before, I use i as a loop so the program doesn't crash if
// one enters something not on the menu or the feature in question isn't implemented
int i;
// This takes the input of which option the user chooses
string input;
i = 0;
while(i < 1) {
cout << "Do you want to calculate:" << endl
<< "1 - The surface area of a cube" << endl << "2 - The surface area of a rectangular prism" << endl
<< "3 - The surface area of a parallelogram prism" << endl;
cin >> input;
// Cube
if(input == "1") {
cout << "What is the length?" << endl;
// The only variable we'll need, as all sides are the same
long double side;
cin >> side;
// Get the area of one side
side = side * side;
// Add up all the sides
side = side * 6;
cout << "The surface area of the cube is:" << endl << side << endl;
i++;
}
// Rectangular prism
else if(input == "2") {
long double length, width, height, surfacearea, temp;
cout << "What is the length of the prism?" << endl;
cin >> length;
cout << "What is the width of the prism?" << endl;
cin >> width;
cout << "What is the height of the prism?" << endl;
cin >> height;
if(length == width && width == height) {
cout << "That's a cube! Use option 1 next time, and save yourself the effort of " << endl
<< "entering the same number thrice!" << endl;
}
// Get one of the longer sides
surfacearea = length * width;
// Two of the longer sides
surfacearea = surfacearea * 2;
// Three of the longer sides
temp = length * height;
// All four longer sides
temp = temp * 2;
// Add them together
surfacearea = surfacearea + temp;
// Now for the square sides
temp = height * width;
// Now for both square sides
temp = temp * 2;
// Add everything together
surfacearea = surfacearea + temp;
cout << "The surface area of the prism is:" << endl << surfacearea << endl;
i++;
}
// Parallelogram prism
else if(input == "3") {
long double base, height, length, surfacearea, temp;
cout << "First we need the area of one end of the prism" << endl;
cout << "What is the base?" << endl;
cin >> base;
cout << "What is the height?" << endl;
cin >> height;
cout << "Excellent, now how long is the prism?" << endl;
cin >> length;
// Get one of the longer sides
surfacearea = length * base;
// Two of the longer sides
surfacearea = surfacearea * 2;
// Three of the longer sides
temp = length * height;
// All four longer sides
temp = temp * 2;
// Add them together
surfacearea = surfacearea + temp;
// Now for the square sides
temp = height * base;
// Now for both square sides
temp = temp * 2;
// Add everything together
surfacearea = surfacearea + temp;
cout << "The surface area of the parallelogram prism is:" << endl << surfacearea << endl;
i++;
}
// End of the while
}
// End of the function
}